package demo.util;

import java.sql.*;

/**
 * Created by Administrator on 2017/12/7 0007.
 */
public class JDBCUtil {
    private static String driver = "org.apache.hive.jdbc.HiveDriver";
    private static String url = "jdbc:hive2://192.168.72.141:10000/default";

    //注册渠道
    static {
        try{
            Class.forName(driver);
        }catch (ClassNotFoundException e){
            throw new ExceptionInInitializerError(e);
        }

    }
    public static Connection getConnection(){
        try{
            return DriverManager.getConnection(url);
        }catch (SQLException e){
            e.printStackTrace();
        }
        return null;
    }

    public static void release(Connection conn, Statement st, ResultSet rs){
        if(null != rs){
            try {
                rs.close();
            }catch (SQLException e){
                e.printStackTrace();
            }finally {
                rs = null;
            }
        }
        if(null != st){
            try {
                st.close();
            }catch (SQLException e){
                e.printStackTrace();
            }finally {
                st = null;
            }

        }
        if(null != conn){
            try {
                conn.close();
            }catch (SQLException e){
                e.printStackTrace();
            }finally {
                conn = null;
            }
        }
    }
}
